﻿using System;

namespace SBToolkit.Utilities.IO
{
    /// <summary>
    /// Provides helper methods to operate with files.
    /// </summary>
    public static class FileHelper
    {
        /// <summary>
        /// Gets readable size for the specified size value.
        /// </summary>
        /// <param name="size">Actual size to get readable size for.</param>
        /// <returns>Readable size.</returns>
        public static string GetReadableSize(long size)
        {
            string[] sizes = { "B", "KB", "MB", "GB" };
            double length = size;
            int order = 0;

            while (length >= 1024 && order + 1 < sizes.Length)
            {
                order++;
                size /= 1024;
            }

            return String.Format("{0:0.##} {1}", length, sizes[order]);
        }
    }
}